<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <title>渠道商信息</title>
    <meta name="viewport" content="width=device-width, initial-scale=1"/>
    <meta name="renderer" content="webkit"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="icon" type="image/png" href="assets/common/i/favicon.ico"/>
    <meta name="apple-mobile-web-app-title" content="渠道商信息"/>
    <link rel="stylesheet" href="Css/amazeui.min.css"/>
    <link rel="stylesheet" href="Css/app.css"/>
    <script src="Scripts/api.js"></script>
    <link rel="stylesheet" href="Css/font_783249_3hfdb7m5w0j.css">
    <script src="Scripts/jquery.min.js"></script>
    <script src="Scripts/font_783249_e5yrsf08rap.js"></script>
    <script>
        BASE_URL = 'https://demo.yiovo.com/';
        STORE_URL = 'index.php?s=/store';
    </script>
</head>

<body data-type="">
<div class="am-g tpl-g">

    <!-- 内容区域 start -->
    <div class="tpl-content-wrapper no-sidebar-second">
        <div class="page-home row-content am-cf">

            <!-- 实时概况 -->
            <div class="row">
                <div class="am-u-sm-12 am-u-md-12 am-u-lg-12 am-margin-bottom">
                    <div class="widget am-cf">
                        <div class="widget-head">
                            <div class="widget-title">区域选择</div>
                        </div>
                        <form action="" id="cityList">
                            <select name="city" id="select1">
                            </select>
                            <select name="city" id="select2">
                            </select>
                            <select name="city" id="select3">
                            </select>

                        </form>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="am-u-sm-12 am-u-md-12 am-u-lg-12 am-margin-bottom">
                    <div class="widget am-cf">
                        <div class="widget-head">
                            <div class="widget-title">区域信息</div>
                        </div>
                        <div class="widget-body am-cf">

                            <div class="am-u-sm-12 am-u-md-6 am-u-lg-3">
                                <div class="widget-card card__violet am-cf">
                                    <div class="card-header">订单总量</div>
                                    <div class="card-body" id ="card-body_num">
                                    </div>
                                </div>
                            </div>

                            <div class="am-u-sm-12 am-u-md-6 am-u-lg-3">
                                <div class="widget-card card__blue am-cf">
                                    <div class="card-header">订单总金额</div>
                                    <div class="card-body" id ="card-body_sum">

                                    </div>
                                </div>
                            </div>
                            <div class="am-u-sm-12 am-u-md-6 am-u-lg-3">
                                <div class="widget-card card__red am-cf">
                                    <div class="card-header"></div>
                                    <div class="card-body">
                                        <div class="card-value"></div>
                                        <div class="card-description"></div>
                                        <span class="card-icon iconfont icon-user"></span>
                                    </div>
                                </div>
                            </div>

                            <div class="am-u-sm-12 am-u-md-6 am-u-lg-3">
                                <div class="widget-card card__primary am-cf">
                                    <div class="card-header"></div>
                                    <div class="card-body">
                                        <div class="card-value"></div>
                                        <div class="card-description"></div>
                                        <span class="card-icon iconfont icon-haoping2"></span>

                                    </div>
                                </div>
                            </div>

                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="am-u-sm-12 am-u-md-12 am-u-lg-12 am-margin-bottom">
                    <div class="widget am-cf">
                        <div class="widget-head">
                            <div class="widget-title">订单信息</div>
                        </div>
                        <table width="100%"
                               class="am-table am-table-centered&#10;                        am-text-nowrap am-margin-bottom-xs">
                            <thead>
                            <tr>
                                <th width="30%" class="goods-detail">商品信息</th>
                                <th width="10%">单价/数量</th>
                                <th width="15%">实付款</th>
                                <th>买家</th>
                                <th>手机号</th>
                                <th>交易状态</th>
                            </tr>
                            </thead>
                            <tbody id="orderItemList">


                            </tbody>

                        </table>


                    </div>
                    <div id  ="pageitem" class="am-u-lg-12 am-cf">

                    </div>
                </div>
            </div>




        </div>
        <script type="text/javascript">

            var getParam = function(name){
                var search = document.location.search;
                var pattern = new RegExp("[?&]"+name+"\=([^&]+)", "g");
                var matcher = pattern.exec(search);
                var items = null;
                if(null != matcher){
                    try{
                        items = decodeURIComponent(decodeURIComponent(matcher[1]));
                    }catch(e){
                        try{
                            items = decodeURIComponent(matcher[1]);
                        }catch(e){
                            items = matcher[1];
                        }
                    }
                }
                return items;
            };
            var pagenum = getParam('pagenum');

            if(pagenum==null)
                pagenum = 1;

            var userRegionID;
            var data = null;
            var getLevel1RegionCallBcak = function (regionlevel1) {
                var select1html = "";
                var shortname = regionlevel1['shortname'];
                select1html+="<option value=\""+regionlevel1['id']+"\">"+shortname+"</option>";
                $("#select1").append(select1html);
            };
            var getLevel2CallBack =function (level2data) {
                var select2html = "";
                var shortname = level2data['shortname'];
                select2html+="<option value=\""+level2data['id']+"\">"+shortname+"</option>";
                $("#select2").append(select2html);
            };
            var getLevel2RegionCallBcak = function (nextregiondata) {
                var select2html ="";
                select2html+="<option value=\"0\">-请选择-</option>";

                for(var i =0;i<nextregiondata.length;i++)
                {
                    var shortname = nextregiondata[i]['shortname'];
                    select2html+="<option value=\""+(nextregiondata[i]['id'])+"\">"+shortname+"</option>";
                }
                $("#select2").append(select2html);

            };
            var getLevel3RegionCallBcak = function (nextregiondata) {
                var select3html="";
                select3html+="<option value=\"0\">-请选择-</option>";

                for(var i =0;i<nextregiondata.length;i++)
                {
                    var shortname = nextregiondata[i]['shortname'];
                    select3html+="<option value=\""+(nextregiondata[i]['id'])+"\">"+shortname+"</option>";
                }
                $("#select3").append(select3html);

            };

            var getRegionCallBack = function (regiondata) {
                var rid  = regiondata['id'];
                var level = regiondata['level'];
                var shortname = regiondata['shortname'];
                if(level==1)
                {
                    var select1html ="";
                    select1html+="<option value=\""+regiondata['id']+"\">"+shortname+"</option>";
                    $("#select1").append(select1html);
                    getAllNextRegionById(rid,getLevel2RegionCallBcak);

                    var select3html = "";
                    select3html+="<option value=\"0\">-请选择-</option>";
                    $("#select3").append(select3html);

                }
                else if(level==2)
                {
                    getLevel1ByRegionId(rid,getLevel1RegionCallBcak);
                    var select2html = "";
                    select2html+="<option value=\""+regiondata['id']+"\">"+shortname+"</option>";
                    $("#select2").append(select2html);
                    getAllNextRegionById(rid,getLevel3RegionCallBcak);
                }
                else if(level==3)
                {
                    getLevel1ByRegionId(rid,getLevel1RegionCallBcak);
                    getLevel2ByRegionId(rid,getLevel2CallBack);
                    var select3html = ""
                    select3html+="<option value=\""+regiondata['id']+"\">"+shortname+"</option>";
                    $("#select3").append(select3html);
                    getRegionsByRegionId(rid,getOrdercallback);
                }

            };


            function getChannelCallBack(channeldata) {
                var regionID = channeldata['region'];
                getRegionById(regionID,getRegionCallBack);
                
            }
            function getUserCallBcak(userdata) {
                var userid = userdata['id'];
                getChannel(userid,getChannelCallBack);

            }
            getUser(getUserCallBcak);
            //alert(data);


            $("#select2").change(function(){
                if($("#select2").val()!=0)
                {
                    var div = document.getElementById("select3");
                    while(div.hasChildNodes()) {
                        div.removeChild(div.firstChild);
                    }
                    var rid = $("#select2").val();
                    getAllNextRegionById(rid,getLevel3RegionCallBcak);
                }
            });


            var ordernum;
            var getnumcallback = function (num) {
                ordernum = num;
            };

            var ImagePath = null;
            var getimageback = function (goodsImage) {
                if(goodsImage.length>0)
                    ImagePath = goodsImage;
            };

            var destate = 0;
            var paystate = 0;
            var getgoodscallback = function (goods) {
                for (var i = 0; i < goods.length; i++) {
                    var goodid = goods[i]['id'];
                    var goodimage = null;
                    var goodname = goods[i]['goods_name'];
                    var goodprice = toDecimal2(goods[i]['goods_price']);
                    summ+=parseFloat(goodprice);
                    var goodnum = goods[i]['total_num'];
                    getOrderImageById(goodid, getimageback);
                    goodimage = ImagePath;

                    if (i == 0) {
                        var tmep_html = "<tr class=\"order-empty\">\n" +
                            "                                        <td colspan=\"6\"></td>\n" +
                            "                                    </tr>";//空白行
                        tmep_html += "<tr>\n" +
                            "                                        <td class=\"am-text-middle am-text-left\" colspan=\"6\">\n" +
                            "                                            <span class=\"am-margin-right-lg\"> " + ordertime + "</span>\n" +
                            "                                            <span class=\"am-margin-right-lg\">订单号：" + orderno + "</span>\n" +
                            "                                        </td>\n" +
                            "                                    </tr>";//订单头部
                        tmep_html += "<tr>\n" +
                            "                                        <td class=\"goods-detail am-text-middle\">\n" +
                            "                                            <div class=\"goods-image\">\n" +
                            "                                                <img alt=\"\" src=\"" + goodimage + "\">\n" +
                            "                                            </div>\n" +
                            "                                            <div class=\"goods-info\">\n" +
                            "                                                <p class=\"goods-title\">" + goodname + "</p>\n" +
                            "                                            </div>\n" +
                            "                                        </td>\n" +
                            "                                        <td class=\"am-text-middle\">\n" +
                            "                                            <p>￥" + goodprice + "</p>\n" +
                            "                                            <p>×" + goodnum + "</p>\n" +
                            "                                        </td>\n" +
                            "                                        <td class=\"am-text-middle\" rowspan=\"" + ordernum + "\">\n" +
                            "                                            <p>￥" + paypricego + "</p>\n" +
                            "                                            <p class=\"am-link-muted\">(含运费：￥" + eprice + ")</p>\n" +
                            "                                        </td>\n" +
                            "                                        <td class=\"am-text-middle\" rowspan=\"" + ordernum + "\">\n" +
                            "                                            <p>用户名：" + username + "</p>\n" +
                            "                                        </td>\n" +
                            "                                        <td class=\"am-text-middle\" rowspan=\""+ ordernum +"\">\n" +
                            "                                                <p>"+userphone+"</p>\n" +
                            "                                            </td>"+
                            "                                        <td class=\"am-text-middle\" rowspan=\"" + ordernum + "\" id=\"orderStateList\">\n" +
                            "\n" + payhtml + dhtml + rhtml +
                            "                                        </td>\n" +
                            "                                    </tr>";//
                        $("#orderItemList").append(tmep_html);

                    } else {
                        var goodhtml = "<tr>\n" +
                            "                                        <td class=\"goods-detail am-text-middle\">\n" +
                            "                                            <div class=\"goods-image\">\n" +
                            "                                                <img alt=\"\" src=\"" + goodimage + "\">\n" +
                            "                                            </div>\n" +
                            "                                            <div class=\"goods-info\">\n" +
                            "                                                <p class=\"goods-title\">" + goodname + "</p>\n" +
                            "                                                <p class=\"goods-spec am-link-muted\"></p>\n" +
                            "                                            </div>\n" +
                            "                                        </td>\n" +
                            "                                        <td class=\"am-text-middle\">\n" +
                            "                                            <p>￥" + goodprice + "</p>\n" +
                            "                                            <p>×" + goodnum + "</p>\n" +
                            "                                        </td>\n" +
                            "                                    </tr>";
                        $("#orderItemList").append(goodhtml);

                    }


                }
                ordernum = 0;
            };
            var ordertime = null;
            var orderno = null;
            var paypricego = null;
            var eprice = null;
            var userid = null;
            var payhtml = null;
            var dhtml = null;
            var rhtml = null;
            var oid = null;
            var OrderCallBcak = function (order) {

                var hid = order['id'];
                oid = hid;
                var ono = order['order_no'];
                var odates = order['create_time'];
                var odate = dateToStr(new Date(odates));
                var totalprice = toDecimal2(order['total_price']);//总共金额
                var payprice = toDecimal2(order['pay_price']);//实付金额
                var expressprice = toDecimal2(order['express_price']);//快递金额
                var uid = order['user_id'];
                var paystatus = parseInt(order['pay_status']);//支付状态
                var deliverystatus = parseInt(order['delivery_status']);//快递状态
                var receiptstatus = parseInt(order['receipt_status']);//接收状态
                var orderstatus = parseInt(order['order_status']);//订单状态

                var paystatehtml = null;

                var deliverystatushtml = null;

                var receiptstatushtml = null;

                var orderstatushtml = null;

                ordertime = odate;
                orderno = ono;
                paypricego = payprice;
                eprice = expressprice;
                userid = uid;


                if (paystatus == 20) {
                    paystate = 1;
                    paystatehtml = "<p>付款状态：\n" +
                        "                                                <span class=\"am-badge&#10;                                                am-badge-success\">\n" +
                        "                                                        已付款</span>\n" +
                        "                                            </p>";
                } else {
                    paystate = 0;
                    paystatehtml = "<p>付款状态：\n" +
                        "                                                <span class=\"am-badge&#10;                                                \">\n" +
                        "                                                        待付款</span>\n" +
                        "                                            </p>";
                }
                if (deliverystatus == 20) {
                    destate = 1;
                    deliverystatushtml = "<p>发货状态：\n" +
                        "                                                <span class=\"am-badge&#10;                                                am-badge-success\">\n" +
                        "                                                        已发货</span>\n" +
                        "                                            </p>";

                } else {
                    destate = 0;
                    deliverystatushtml = "<p>发货状态：\n" +
                        "                                                <span class=\"am-badge&#10;                                                \">\n" +
                        "                                                        待发货</span>\n" +
                        "                                            </p>";
                }
                if (receiptstatus == 10) {
                    receiptstatushtml = "<p>收货状态：\n" +
                        "                                                <span class=\"am-badge&#10;                                                \">\n" +
                        "                                                        待收货</span>\n" +
                        "                                            </p>";

                } else {
                    receiptstatushtml = "<p>收货状态：\n" +
                        "                                                <span class=\"am-badge&#10;                                                am-badge-success\">\n" +
                        "                                                        已收货</span>\n" +
                        "                                            </p>";
                }

                payhtml = paystatehtml;
                dhtml = deliverystatushtml;
                rhtml = receiptstatushtml;

                getgoodsNum(hid, getnumcallback);
                getgoods(hid, getgoodscallback);
            };

            var username = null;
            var userphone = null;
            var summ = 0.00;

            var getOrdercallback = function (wxhelpdata) {

                var total = wxhelpdata.length;
                var div = document.getElementById("card-body_num");
                while(div.hasChildNodes()) {
                    div.removeChild(div.firstChild);
                }
                var totalhtml = "<div class=\"card-value\">"+total+"</div>\n" +
                    "                                        <div class=\"card-description\">已付款订单总数量</div>\n" +
                    "                                        <span class=\"card-icon iconfont icon-order\"></span>";
                $('#card-body_num').append(totalhtml);
                for (var n = 0; n < wxhelpdata.length; n++) {
                    username = wxhelpdata[n]['name'];
                    userphone = wxhelpdata[n]['phone'];
                    var orderid = wxhelpdata[n]['order_id'];
                    getOrderByid(orderid,OrderCallBcak);
                }
                var div = document.getElementById("card-body_sum");
                while(div.hasChildNodes()) {
                    div.removeChild(div.firstChild);
                }
                var sumhtml = "<div class=\"card-value\">"+toDecimal2(summ)+"元</div>\n" +
                    "                                        <div class=\"card-description\">当前该区域订单总金额</div>\n" +
                    "                                        <span class=\"card-icon iconfont icon-goods\"></span>";
                $('#card-body_sum').append(sumhtml);

            };


            $("#select3").change(function(){
                if($("#select3").val()!=0)
                {
                    var rid = $("#select3").val();
                    getRegionsByRegionId(rid,getOrdercallback);

                }
            });





            function dateToStr(datetime) {

                var year = datetime.getFullYear();
                var month = datetime.getMonth() + 1;
                var date = datetime.getDate();
                var hour = datetime.getHours();
                var minutes = datetime.getMinutes();
                var second = datetime.getSeconds();

                if (month < 10) {
                    month = "0" + month;
                }
                if (date < 10) {
                    date = "0" + date;
                }
                if (hour < 10) {
                    hour = "0" + hour;
                }
                if (minutes < 10) {
                    minutes = "0" + minutes;
                }
                if (second < 10) {
                    second = "0" + second;
                }

                var time = year + "-" + month + "-" + date + " " + hour + ":" + minutes + ":" + second;
                return time;
            }

            //制保留2位小数，如：2，会在2后面补上00.即2.00
            function toDecimal2(x) {
                var f = parseFloat(x);
                if (isNaN(f)) {
                    return false;
                }
                var f = Math.round(x * 100) / 100;
                var s = f.toString();
                var rs = s.indexOf('.');
                if (rs < 0) {
                    rs = s.length;
                    s += '.';
                }
                while (s.length <= rs + 2) {
                    s += '0';
                }
                return s;
            }

        </script>
    </div>
    <!-- 内容区域 end -->

</div>



</body></html>